// 银行融资管理
var Bankdebit = Ext.data.Record.create([
	{name : 'tid',mapping : 'tid',type : 'int'}, 
	{name : 'pid',mapping : 'fid',type : 'int'}, 
	{name : 'cnumber',mapping : 'cnumber',type : 'string'}, 
	{name : 'cardnumber',mapping : 'cardnumber',type : 'string'}, 
	{name : 'csum',mapping : 'csum',type : 'float'},  
	{name : 'loanid',mapping : 'loanid',type : 'int'}, 
	{name : 'loanname',mapping : 'loanname',type : 'string'},  
	{name : 'rate',mapping : 'rate',type : 'float'}, 
	{name : 'interest',mapping : 'interest',type : 'float'},
	{name : 'charge',mapping : 'charge',type : 'float'},
	{name : 'debtorid',mapping : 'debtorid',type : 'int'},
	{name : 'debtorname',mapping : 'debtorname',type : 'string'},
	{name : 'startdate',mapping : 'startdate',type : 'date'},
	{name : 'closedate',mapping : 'closedate',type : 'date'},
	{name : 'accountid',mapping : 'accountid',type : 'int'},
	{name : 'accountname',mapping : 'accountname',type : 'string'},
	{name : 'status',mapping : 'status',type : 'string'},
	{name : 'createtime',mapping : 'createtime',type : 'date'},
	{name : 'memo',mapping : 'memo',type : 'string'}
	]);

var cm_bankdebit = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
	header : '合同号',
	width : 120,
	dataIndex : 'cnumber'
}, {
	header : '填写日期',
	width : 90,
	dataIndex : 'createtime',
	sortable : true,
	renderer: renderDate
},{
	header : '贷款银行',
	width : 80,
	dataIndex : 'loanname',
	sortable : false
},{
	header : '贷款日期',
	width : 90,
	dataIndex : 'startdate',
	renderer: renderDate,
	sortable:true
	
},{
	header : '到期日期',
	width : 90,
	dataIndex : 'closedate',
	renderer: renderDate,
	sortable:true
	
},{
	header : '贷款总额',
	width : 80,
	dataIndex : 'csum',
	sortable : false
},{
	header : '利率%',
	width : 60,
	dataIndex : 'rate',
	sortable : true
},{
	header : '利息支出',
	width : 60,
	dataIndex : 'interest',
	sortable : true
},{
	header : '投资费用',
	width : 60,
	dataIndex : 'charge',
	sortable : true
},{
	header : '状态',
	width : 60,
	dataIndex : 'status',
	sortable : true
},{
	header : '备注',
	width : 60,
	dataIndex : 'memo',
	sortable : true
}]);

cm_bankdebit.defaultSortable = true;

var btn_add_bankdebit = new Ext.Button({
	text : '增加贷款',
	iconCls : 'icon-add',
	handler : function() {
		window_add_bankdebit.show();
	}
});

var btn_edit_bankdebit = new Ext.Button({
	text : '修改贷款',
	iconCls : 'icon-edit',
	handler : function() {
		var record = grid_bankdebit.getSelectionModel().getSelected();
		if (record) {
			if(record.data.status=="未还"){
				window_edit_bankdebit.show();
			}else{
				Ext.Msg.show({title : '错误提示',
							msg : '这笔银行融资已处理,不能修改!',
							buttons : Ext.Msg.OK,
							icon : Ext.Msg.ERROR
							});
			}
		}
	}
});


var btn_del_bankdebit = new Ext.Button({
	text : '删除贷款',
	iconCls : 'icon-del',
	handler : function() {
		var record = grid_bankdebit.getSelectionModel().getSelected();
		if (record) {
			if(record.data.status=="未还"){
			Ext.Msg.confirm('确认删除这笔贷款', '你确定删除该条记录?', function(btn) {
				if (btn == 'yes') {
					Ext.Ajax.request({
						url : '/bankdebit/deleteBankdebit.action',
						params : {tid : record.data.tid},
						success : function() {
							grid_bankdebit.getStore().remove(record);
							ds_bankdebit.load({params : {start : 0,limit : 20}});
						},
						failure : function() {
							Ext.Msg.show({
								title : '错误提示',
								msg : '删除时发生错误,这笔投资已结清或您没有删除的权限!',
								buttons : Ext.Msg.OK,
								icon : Ext.Msg.ERROR
							});
						}
					});
				}
			});
			}else{
				Ext.Msg.show({title : '错误提示',
								msg : '这笔投资已结清,不能删除!',
								buttons : Ext.Msg.OK,
								icon : Ext.Msg.ERROR
								});
			}
		}
	}
});

var btn_intert_bankdebit = new Ext.Button({
	text : '支付银行利息',
	iconCls : 'icon-edit',
	width : 100,
	handler : function() {
		var record = grid_bankdebit.getSelectionModel().getSelected();
		if (record) {
			if(record.data.status=="已结清"){
				Ext.Msg.show({title : '错误提示',
							msg : '这笔融资已结清!',
							buttons : Ext.Msg.OK,
							icon : Ext.Msg.ERROR
							});
			}else{
				window_intert_bankdebit.show();
				
			}
		}
	}
});

var btn_giveback_bankdebit = new Ext.Button({
	text : '归还贷款',
	iconCls : 'icon-edit',
	handler : function() {
		var record = grid_bankdebit.getSelectionModel().getSelected();
		if (record) {
			Ext.Msg.confirm('确认归还贷款', '你确定归还这笔贷款?', function(btn) {
				if (btn == 'yes') {
					Ext.Ajax.request({
						url : '/bankdebit/givebackBankdebit.action',
						params : {tid : record.data.tid},
						success : function() {ds_bankdebit.load({params : {start : 0,limit : 20}});},
						failure : function() {
							Ext.Msg.show({
								title : '错误提示',
								msg : '归还时发生错误,这笔贷款已结清!',
								buttons : Ext.Msg.OK,
								icon : Ext.Msg.ERROR
							});
						}
					});
				}
			});
		}
	}
});

var awoke_search_bankdebit = new Ext.form.ComboBox({
		name : 'awokeBankdebit',
		width:150,
		editable : false,
		store : new Ext.data.SimpleStore({
			data : [['全部',0],['三十天内应还银行借款', 30], ['半年内应还银行借款',180],['三个季度内应还银行借款',270],['一年内应还银行借款',360]],
			fields : ['text', 'value']
		}),
		displayField : 'text',
		valueField : 'value',
		hiddenName:'awokeDays',
		mode : 'local',
		triggerAction : 'all',
		emptyText : '全部银行借款',
		listeners : {
		'select' : function(combo, record, index) {
			ds_bankdebit.baseParams.awokeDays = awoke_search_bankdebit.getValue(); 
			ds_bankdebit.baseParams.conditions = text_search_bankdebit.getValue(); 
			ds_bankdebit.load({params : {start : 0,limit : 20}});
			}
		}
});
var text_search_bankdebit = new Ext.form.TextField({
	name : 'textSearchBankdebit',
	emptyText : '根据合同号模糊查询!',
	width:200,
	listeners : {
		'specialkey' : function(field, e) {
			if (e.getKey() == Ext.EventObject.ENTER) {
				searchBankdebit();
			}
		}
	}
});

var searchBankdebit = function() {
	ds_bankdebit.baseParams.awokeDays = awoke_search_bankdebit.getValue(); 
	ds_bankdebit.baseParams.conditions = text_search_bankdebit.getValue(); 
	ds_bankdebit.load({params : {start : 0,limit : 20}});
}

var btn_search_bankdebit = new Ext.Button({
	text : '查询',
	iconCls : 'icon-search',
	handler : searchBankdebit
});

var ds_bankdebit = new Ext.data.Store({
	url : '/bankdebit/findAllBankdebit.action',
	reader : new Ext.data.JsonReader({totalProperty : 'totalProperty',root : 'root'}, 
	[{name : 'tid',mapping : 'tid',type : 'int'}, 
	{name : 'pid',mapping : 'fid',type : 'int'}, 
	{name : 'cnumber',mapping : 'cnumber',type : 'string'}, 
	{name : 'cardnumber',mapping : 'cardnumber',type : 'string'}, 
	{name : 'csum',mapping : 'csum',type : 'float'},  
	{name : 'loanid',mapping : 'loanid',type : 'int'}, 
	{name : 'loanname',mapping : 'loanname',type : 'string'},  
	{name : 'rate',mapping : 'rate',type : 'float'}, 
	{name : 'interest',mapping : 'interest',type : 'float'},
	{name : 'charge',mapping : 'charge',type : 'float'},
	{name : 'debtorid',mapping : 'debtorid',type : 'int'},
	{name : 'debtorname',mapping : 'debtorname',type : 'string'},
	{name : 'startdate',mapping : 'startdate',type : 'string'},
	{name : 'closedate',mapping : 'closedate',type : 'string'},
	{name : 'accountid',mapping : 'accountid',type : 'int'},
	{name : 'accountname',mapping : 'accountname',type : 'string'},
	{name : 'status',mapping : 'status',type : 'string'},
	{name : 'createtime',type : 'string'},
	{name : 'memo',type : 'string'}
	])
});

var grid_bankdebit = new Ext.grid.EditorGridPanel({
	title : '银行融资管理',
	iconCls : 'icon-grid',
	loadMask : {msg : '数据加载中...'},
	width:600,
	region : 'center',
	cm : cm_bankdebit,
	ds : ds_bankdebit,
	sm : new Ext.grid.RowSelectionModel({singleSelect : true}),
	enableColumnMove : false,
	trackMouseOver : false,
	frame : true,
	clicksToEdit : 1,
	tbar : [btn_add_bankdebit,btn_edit_bankdebit, btn_del_bankdebit, '-',btn_intert_bankdebit,btn_giveback_bankdebit,'-',text_search_bankdebit,'-',awoke_search_bankdebit,'-', btn_search_bankdebit],
	bbar : new Ext.PagingToolbar({
		pageSize : 20,
		store : ds_bankdebit,
		displayInfo : true,
		displayMsg : '第 {0} - {1} 条  共 {2} 条',
		emptyMsg : "没有记录",
		items:[{   
                text: '导出到Excel',   
                tooltip: 'Excel',   
                handler: bankdebitExport // 
                        }]
	}),listeners : {
		'click' : function(){
			var record = this.getSelectionModel().getSelected();
			ds_bankdebitt_data.baseParams.tid = record.data.tid; 
			ds_bankdebitt_data.load({params : {start : 0,limit : 1000}});
		}
	}
});

function bankdebitExport(){
	doExport(grid_bankdebit);
}

var window_add_bankdebit = new Ext.Window({
	title : '增加贷款',
	width : 320,
	resizable : false,
	autoHeight : true,
	modal : true,
	closeAction : 'hide',
	listeners : {
		'hide' : function() {
			this.setTitle('增加贷款');
			this.findById('bankdebit.cnumber').ownerCt.form.reset();
		}
	},
	items : [new Ext.FormPanel({
		border : false,
		baseCls : 'x-plain',
		bodyStyle : 'padding:5px 5px 0',
		labelAlign : 'right',
		labelWidth : 70,
		defaults : {anchor : '93%',msgTarget : 'side'},
		defaultType : 'textfield',
		items : [{
		    fieldLabel : '合同号',
			id : 'bankdebit.cnumber',
			name : 'bankdebit.cnumber',
			allowBlank : false,
			minLength : 5,
		 	maxLength : 32},
		 	{
		   	xtype : 'combo',
			fieldLabel : '贷款银行',
			name : 'loanid',
			hiddenName : 'bankdebit.loanid',
			valueField : 'tid',
		    displayField : 'name',
		    mode : 'remote',
			store : ds_loan_select,
			selectOnFocus : true,
			editable : false,
			allowBlank : false,
			triggerAction : 'all',
			loadingText : '加载中...',
			emptyText : '请选择贷款银行',
			listeners : {
				'select' : function(combo, record, index) {
					this.ownerCt.ownerCt.form.findField('bankdebit.loanname').setValue(record.data.name);
				},
				'expand' : function(){
					ds_loan_select.load();
				}
			}
		   }, {xtype : 'hidden',name : 'bankdebit.loanname'}
		   , {
		   	xtype : 'datefield',
			fieldLabel : '贷款日期',
			id : 'bankdebit.startdate',
			name : 'bankdebit.startdate',
			format : 'Y-m-d',
			hiddenName : 'bankdebit.startdate',
			allowBlank : false
		}, {
		   	xtype : 'datefield',
			fieldLabel : '到期日期',
			id : 'bankdebit.closedate',
			name : 'bankdebit.closedate',
			hiddenName : 'bankdebit.closedate',
			format : 'Y-m-d',
			vtype:'dttypes',//自定义的验证类型
            vtypeText:'到期日期应该比贷款日期迟',
            confirmTo:'bankdebit.startdate',//要比较的另外一个的组件的id
			allowBlank : false
		},{
		   	xtype : 'combo',
			fieldLabel : '存储帐号',
			name : 'cardnumber',
			hiddenName : 'bankdebit.cardnumber',
			valueField : 'cardnumber',
		    displayField : 'cardnumber',
		    mode : 'remote',
			store : ds_account_select,
			selectOnFocus : true,
			editable : false,
			allowBlank : false,
			triggerAction : 'all',
			loadingText : '加载中...',
			emptyText : '请选择存储帐号',
			listeners : {
				'select' : function(combo, record, index) {
					this.ownerCt.ownerCt.form.findField('bankdebit.accountname').setValue(record.data.username);
					this.ownerCt.ownerCt.form.findField('bankdebit.accountid').setValue(record.data.tid);
					this.ownerCt.ownerCt.form.findField('bankdebit.debtorname').setValue(record.data.name);
					this.ownerCt.ownerCt.form.findField('bankdebit.debtorid').setValue(record.data.owner);
				},
				'expand' : function(){
					ds_account_select.load();
				}
			}
		   },
		    {
		    fieldLabel : '账户开户人',
			id : 'bankdebit.accountname',
			name : 'bankdebit.accountname',
			allowBlank : false,
			readOnly:true},
		    {xtype : 'hidden',name : 'bankdebit.accountid'}, 
		    {fieldLabel : '贷款单位',
			id : 'bankdebit.debtorname',
			name : 'bankdebit.debtorname',
			allowBlank : false,
			readOnly:true},
		    {xtype : 'hidden',name : 'bankdebit.debtorid'}, 
		   {
		  	xtype:'numberfield',
		 	fieldLabel : '贷款金额',
		 	name : 'bankdebit.csum',
		 	allowBlank : false,
		 	minLength : 1,
		 	maxLength : 12
		  },
		  {
		  	xtype:'numberfield',
		 	fieldLabel : '利率%',
		 	name : 'bankdebit.rate',
		 	allowBlank : false,
		 	minLength : 1,
		 	maxLength : 12
		  },
		  {
		  	xtype:'numberfield',
		 	fieldLabel : '投资费用',
		 	name : 'bankdebit.charge',
		 	allowBlank : false,
		 	minLength : 1,
		 	maxLength : 12
		  },
		   {xtype: 'textarea',
		   	fieldLabel : '备注',
		   name : 'bankdebit.memo',
		   maxLength : 60
		   }
		],
		buttonAlign : 'right',
		minButtonWidth : 60,
		buttons : [{
			text : '添加',
			handler : function(btn) {
				var frm = this.ownerCt.ownerCt.form;
				if (frm.isValid()) {
					btn.disable();
					var unfield = frm.findField('bankdebit.cardnumber');
					frm.submit({
						waitTitle : '请稍候',
						url : '/bankdebit/saveBankdebit.action',
						waitMsg : '正在提交表单数据,请稍候...',
						success : function(form, action) {
							window_add_bankdebit.hide();
							ds_bankdebit.load({params : {start : 0,limit : 20}});
							btn.enable();
						},
						failure : function() {
							Ext.Msg.show({
								title : '错误提示',
								msg : '发生不明错误，请与管理员联系!',
								buttons : Ext.Msg.OK,
								fn : function() {
									unfield.focus(true);
									btn.enable();
								},
								icon : Ext.Msg.ERROR
							});
						}
					});
				}
			}
		}, {text : '重置',handler : function() {this.ownerCt.ownerCt.form.reset();}
		}, {text : '取消',handler : function() {
			this.ownerCt.ownerCt.ownerCt.hide();
			ds_bankdebit.load({params : {start : 0,limit : 20}});}
		}]
	})]
});

var window_edit_bankdebit = new Ext.Window({
	title : '修改贷款',
	width : 320,
	resizable : false,
	autoHeight : true,
	modal : true,
	closeAction : 'hide',
	listeners : {
		'hide' : function() {
			this.setTitle('修改贷款');
			this.findById('bankdebitd.cnumber').ownerCt.form.reset();
		},
		'show' : function(){
			var record = grid_bankdebit.getSelectionModel().getSelected();
			this.findById('bankdebitd.tid').setValue(record.data.tid);
			this.findById('bankdebitd.cnumber').setValue(record.data.cnumber);
			this.findById('bankdebitd.loanname').setValue(record.data.loanname);
			this.findById('bankdebitd.loanid').setValue(record.data.loanid);
			this.findById('bankdebitd.startdate').setValue(renderDate(record.data.startdate));
			this.findById('bankdebitd.closedate').setValue(renderDate(record.data.closedate));
			this.findById('bankcardnumber').setValue(record.data.cardnumber);
			this.findById('bankdebitd.accountname').setValue(record.data.accountname);
			this.findById('bankdebitd.accountid').setValue(record.data.accountid);
			this.findById('bankdebitd.debtorname').setValue(record.data.debtorname);
			this.findById('bankdebitd.debtorid').setValue(record.data.debtorid);
			this.findById('bankdebitd.csum').setValue(record.data.csum);
			this.findById('bankdebitd.rate').setValue(record.data.rate);
			this.findById('bankdebitd.charge').setValue(record.data.charge);
			this.findById('bankdebitd.memo').setValue(record.data.memo);
		}
	},
	items : [new Ext.FormPanel({
		border : false,
		baseCls : 'x-plain',
		bodyStyle : 'padding:5px 5px 0',
		labelAlign : 'right',
		labelWidth : 70,
		defaults : {anchor : '93%',msgTarget : 'side'},
		defaultType : 'textfield',
		items : [{xtype : 'hidden',id:'bankdebitd.tid',name : 'bankdebit.tid'}, 
			{ fieldLabel : '合同号',
			id : 'bankdebitd.cnumber',
			name : 'bankdebit.cnumber',
			allowBlank : false,
			minLength : 5,
		 	maxLength : 32},
		 	{
		   	xtype : 'combo',
			fieldLabel : '贷款银行',
			id: 'bankdebitd.loanname',
			name : 'bankdebit.loanname',
			hiddenName : 'bankdebit.loanname',
			valueField : 'name',
		    displayField : 'name',
		    mode : 'remote',
			store : ds_loan_select,
			selectOnFocus : true,
			editable : false,
			allowBlank : false,
			triggerAction : 'all',
			loadingText : '加载中...',
			emptyText : '请选择贷款银行',
			listeners : {
				'select' : function(combo, record, index) {
					this.ownerCt.ownerCt.form.findField('bankdebitd.loanid').setValue(record.data.tid);
				},
				'expand' : function(){
					ds_loan_select.load();
				}
			}
		   }, {xtype : 'hidden',id:'bankdebitd.loanid',name : 'bankdebit.loanid'}
		   , {
		   	xtype : 'datefield',
			fieldLabel : '贷款日期',
			id : 'bankdebitd.startdate',
			name : 'bankdebit.startdate',
			format : 'Y-m-d',
			hiddenName : 'bankdebit.startdate',
			allowBlank : false
		}, {
		   	xtype : 'datefield',
			fieldLabel : '到期日期',
			id : 'bankdebitd.closedate',
			name : 'bankdebit.closedate',
			hiddenName : 'bankdebit.closedate',
			format : 'Y-m-d',
			vtype:'dttypes',//自定义的验证类型
            vtypeText:'到期日期应该比贷款日期迟',
            confirmTo:'bankdebitd.startdate',//要比较的另外一个的组件的id
			allowBlank : false
		},{
		   	xtype : 'combo',
			fieldLabel : '存储帐号',
			id:'bankcardnumber',
			name : 'bankcardnumber',
			hiddenName : 'bankdebit.cardnumber',
			valueField : 'cardnumber',
		    displayField : 'cardnumber',
		    mode : 'remote',
			store : ds_account_select,
			selectOnFocus : true,
			editable : false,
			allowBlank : false,
			triggerAction : 'all',
			loadingText : '加载中...',
			emptyText : '请选择存储帐号',
			listeners : {
				'select' : function(combo, record, index) {
					this.ownerCt.ownerCt.form.findField('bankdebit.accountname').setValue(record.data.username);
					this.ownerCt.ownerCt.form.findField('bankdebit.accountid').setValue(record.data.tid);
					this.ownerCt.ownerCt.form.findField('bankdebit.debtorname').setValue(record.data.name);
					this.ownerCt.ownerCt.form.findField('bankdebit.debtorid').setValue(record.data.owner);
				},
				'expand' : function(){
					ds_account_select.load();
				}
			}
		   },
		    {
		    fieldLabel : '账户开户人',
			id : 'bankdebitd.accountname',
			name : 'bankdebit.accountname',
			allowBlank : false,
			readOnly:true},
		    {xtype : 'hidden',id:'bankdebitd.accountid',name : 'bankdebit.accountid'}, 
		    {fieldLabel : '贷款单位',
			id : 'bankdebitd.debtorname',
			name : 'bankdebit.debtorname',
			allowBlank : false,
			readOnly:true},
		    {xtype : 'hidden',id:'bankdebitd.debtorid',name : 'bankdebit.debtorid'}, 
		   {
		  	xtype:'numberfield',
		 	fieldLabel : '贷款金额',
		 	id:'bankdebitd.csum',
		 	name : 'bankdebit.csum',
		 	allowBlank : false,
		 	minLength : 1,
		 	maxLength : 12
		  },
		  {
		  	xtype:'numberfield',
		 	fieldLabel : '利率%',
		 	id:'bankdebitd.rate',
		 	name : 'bankdebit.rate',
		 	allowBlank : false,
		 	minLength : 1,
		 	maxLength : 12
		  },
		  {
		  	xtype:'numberfield',
		 	fieldLabel : '投资费用',
		 	id:'bankdebitd.charge',
		 	name : 'bankdebit.charge',
		 	allowBlank : false,
		 	minLength : 1,
		 	maxLength : 12
		  },
		   {xtype: 'textarea',
		   	fieldLabel : '备注',
		   	id:'bankdebitd.memo',
		   name : 'bankdebit.memo',
		   maxLength : 60
		   }
		],
		buttonAlign : 'right',
		minButtonWidth : 60,
		buttons : [{
			text : '保存',
			handler : function(btn) {
				var frm = this.ownerCt.ownerCt.form;
				if (frm.isValid()) {
					btn.disable();
					var unfield = frm.findField('bankdebitd.cardnumber');
					frm.submit({
						waitTitle : '请稍候',
						url : '/bankdebit/updateBankdebit.action',
						waitMsg : '正在提交表单数据,请稍候...',
						success : function(form, action) {
							window_edit_bankdebit.hide();
							ds_bankdebit.load({params : {start : 0,limit : 20}});
							btn.enable();
						},
						failure : function() {
							Ext.Msg.show({
								title : '错误提示',
								msg : '发生不明错误，请与管理员联系!',
								buttons : Ext.Msg.OK,
								fn : function() {
									unfield.focus(true);
									btn.enable();
								},
								icon : Ext.Msg.ERROR
							});
						}
					});
				}
			}
		}, {text : '取消',handler : function() {
			this.ownerCt.ownerCt.ownerCt.hide();
			ds_bankdebit.load({params : {start : 0,limit : 20}});}
		}]
	})]
});

var window_intert_bankdebit = new Ext.Window({
	title : '归还银行利息',
	width : 320,
	resizable : false,
	autoHeight : true,
	modal : true,
	closeAction : 'hide',
	listeners : {
		'hide' : function() {
			this.setTitle('归还银行利息');
			this.findById('bhx.tid').ownerCt.form.reset();
		},
		'show' :function(){
			var record = grid_bankdebit.getSelectionModel().getSelected();
			this.findById('bhx.tid').setValue(record.data.tid);
			this.findById('bhx.loanname').setValue(record.data.loanname);
			this.findById('bhx.cnumber').setValue(record.data.cnumber);
			this.findById('bhx.interest').setValue(record.data.interest);
			this.findById('bhx.lixi').setValue(0);
		}
	},
	items : [new Ext.FormPanel({
		border : false,
		baseCls : 'x-plain',
		bodyStyle : 'padding:5px 5px 0',
		labelAlign : 'right',
		labelWidth : 70,
		defaults : {anchor : '93%',msgTarget : 'side'},
		defaultType : 'textfield',
		items : [{xtype : 'hidden',id:'bhx.tid',name : 'bankdebit.tid'},
			{ fieldLabel : '合同号',
			id : 'bhx.cnumber',
			name : 'bankdebit.cnumber',
			allowBlank : false,
			readOnly :true,
			minLength : 5,
		 	maxLength : 32},
		 	{ fieldLabel : '还款人',
			id : 'bhx.loanname',
			name : 'bankdebit.loanname',
			allowBlank : false,
			readOnly :true,
			minLength : 1,
		 	maxLength : 32},
		  {
		  	xtype:'numberfield',
		 	fieldLabel : '需还利息',
		 	id:'bhx.interest',
		 	name : 'bhx.interest',
		 	allowBlank : false,
		 	readOnly :true,
		 	minLength : 1,
		 	maxLength : 12
		  },
		  {
		  	xtype:'numberfield',
		 	fieldLabel : '归还利息',
		 	id:'bhx.lixi',
		 	name : 'bankdebit.interest',
		 	allowBlank : false,
		 	vtype:'balance',//自定义的验证类型
            vtypeText:'超过所需支付的利息',
            confirmTo:'bhx.interest',//要比较的另外一个的组件的id
		 	minLength : 1,
		 	maxLength : 12
		  }
		],
		buttonAlign : 'right',
		minButtonWidth : 60,
		buttons : [{
			text : '归还利息',
			handler : function(btn) {
				var frm = this.ownerCt.ownerCt.form;
				if (frm.isValid()) {
					btn.disable();
					var unfield = frm.findField('bhx.tid');
					frm.submit({
						waitTitle : '请稍候',
						url : '/bankdebit/givebackIntertBankdebit.action',
						waitMsg : '正在提交表单数据,请稍候...',
						success : function(form, action) {
							btn.enable();
							window_intert_bankdebit.hide();
							ds_bankdebit.load({params : {start : 0,limit : 20}});
						},
						failure : function() {
							Ext.Msg.show({
								title : '错误提示',
								msg : '发生不明错误，请与管理员联系!',
								buttons : Ext.Msg.OK,
								fn : function() {
									unfield.focus(true);
									btn.enable();
								},
								icon : Ext.Msg.ERROR
							});
						}
					});
				}
			}
		},{text : '取消',handler : function() {
			this.ownerCt.ownerCt.ownerCt.hide();
			ds_bankdebit.load({params : {start : 0,limit : 20}});
		}
		}]
	})]
});

var cm_bankdebitt_detail = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
	header : '合同号',
	width : 120,
	dataIndex : 'cnumber'
},{
	header : '借款人',
	width : 80,
	dataIndex : 'loanname',
	sortable : false
},{
	header : '归还利息',
	width : 60,
	dataIndex : 'interest',
	renderer:renderDelay,
	sortable : true
},{
	header : '归还日期',
	width : 90,
	dataIndex : 'createtime',
	renderer: renderDate,
	sortable : true
}]);

cm_bankdebitt_detail.defaultSortable = true;
var grid_bankdebitt_detail = new Ext.grid.EditorGridPanel({
	title : '还息纪录',
	iconCls : 'icon-grid',
	region: 'center',
	loadMask : {msg : '数据加载中...'},
	width:400,
	cm : cm_bankdebitt_detail,
	ds : ds_bankdebitt_data,
	sm : new Ext.grid.RowSelectionModel({singleSelect : true}),
	enableColumnMove : false,
	trackMouseOver : false,
	frame : true,
	clicksToEdit : 1
});
    
var bankdebit_tabs=new Ext.TabPanel({
        activeTab:0,
        region: 'south',
        height:300,
        frame:true,
        items:[grid_bankdebitt_detail],
        listeners : {
		'tabchange ' : function(tabs,tab){
			//var record = this.getSelectionModel().getSelected();
			//ds_bankdebitt_data.baseParams.tid = record.data.tid(); 
			//ds_bankdebitt_data.load({params : {start : 0,limit : 1000}});
			
		}
	}
 });

var p_bankdebit = {
	id : 'bankdebit-panel',
	border : false,
	layout : 'border',
	items : [grid_bankdebit,bankdebit_tabs]
};